<?php

/**
 * @name DashboardController.php
 */
class DashboardController extends AppController
{
    # Controller name

    var $name = 'Dashboard';
    # set the model to use
    var $uses = array('User','MenuGroup','Contact','ContactGroup','SmsMeta','SmsOutbox','Faq','Country');
    # Set the layout to use
    var $layout = 'dashboard_layout';

    function index(){
        $user_id = $this->Auth->user('id');
        $report = array();

        $year_month = date('Y-m');
        $year_month_format = date('M/y',strtotime(date('Y-m')));


        //Credit Bal
        $report['credit_bal'] = $this->User->getCreditBal($user_id);
        //Total Contacts
        $report['contacts_total'] = $this->Contact->getTotal($user_id);
       //Total Group Contacts
        $report['contact_group_total'] = $this->ContactGroup->getTotal($user_id);
        //Total SMS delivered per month
        $report['delivered_total'] = $this->SmsOutbox->getSMSTotalDelivered($user_id,$year_month);
        //Total SMS pending per month
        $report['pending_total'] = $this->SmsOutbox->getSMSTotalPending($user_id,$year_month);

        $year = date('Y');
        $graph = $this->SmsOutbox->getSMSsatatitics($user_id,$year);
        //$graph = array();

        $faqs = $this->Faq->getFaqs();

        $country_operators = $this->Country->getCountryAndOperatorForWidget();

        /*$from = array('email'=>'kuulmek@gmail.com','name'=>'Gideon Amissah');
        $to = 'kuulmek@yahoo.com';
        $subject = 'The Test Mailer';
        $body = 'We are testing PHPMailer';
        $res = $this->PHPMailer->sendMail($from,$to,$subject,$body);*/


        $page_title = 'Dashboard';
        $page_summary = 'Daily Statistics';
        $page_icon = 'iconfa-dashboard';
        $this->set(compact('page_title','page_summary','page_icon','permissions','report','year_month_format','graph','year','faqs','country_operators'));
    }



}